package com.llh.activitidemo.activititest;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;

/**
 * <h2>Demo1</h2>
 * <p>Description</p>
 * <p>CreatedAt: 2020-04-14 23:20</p>
 * <p><a href="mailto:forever2y_y@163.com">SendMailToMe</a></p>
 *
 * @author llh
 */
@SpringBootTest
public class Demo1 {

    @Autowired
    RepositoryService repositoryService;


    @Autowired
    RuntimeService runtimeService;

    /**
     * 新建一个简单的流程
     */
    @Test
    public void testAddProcess() {
        Deployment deployment = repositoryService.createDeployment()
            .name("离职流程")
            .addClasspathResource("process/leave.bpmn")
            .deploy();
        System.out.println("部署ID：" + deployment.getId());
        System.out.println("部署名称：" + deployment.getName());
    }

    /**
     * 简单的流程分配
     */
    @Test
    public void testAssign() {
        String userKey = "PTM";//脑补一下这个是从前台传过来的数据
        String processDefinitionKey = "leave";//每一个流程有对应的一个key这个是某一个流程内固定的写在bpmn内的
        HashMap<String, Object> variables = new HashMap<>();
        variables.put("userKey", userKey);//userKey在上文的流程变量中指定了
        variables.put("day", 2);
        variables.put("users", "a");
        ProcessInstance instance = runtimeService
            .startProcessInstanceByKey(processDefinitionKey, variables);
        System.out.println("流程实例ID:" + instance.getId());
        System.out.println("流程定义ID:" + instance.getProcessDefinitionId());
    }
}
